Setup lighttpd:
  group.present:
    - name: lighttpd
    - gid: 99999

  user.present:
    - name: lighttpd
    - shell: /sbin/nologin
    - uid: 99999
    - gid: 99999
    - unique: false
    - gid_from_name: true

  pkg.installed:
    - pkgs:
      - lighttpd
      - lighttpd-fastcgi

Copy default lighttpd config lighttp.conf:
  file.managed:
    - name: /etc/lighttpd/lighttpd.conf
    - source: salt://lighttpd/files/default.conf
    - template: jinja

{% for vhosts_conf in salt['pillar.get']('vhost', {}) %}
Generate {{ vhosts_conf }} vhost config for lighttpd:
  file.managed:
    - name: /etc/lighttpd/vhosts.d/{{ vhosts_conf }}.conf
    - source: salt://lighttpd/files/vhost.d/vhost.conf.jinja
    - template: jinja
    - context:
        app_name: {{ vhosts_conf }}

Append {{ vhosts_conf }} vhost config to main lighttpd.conf:
  file.append:
    - name: /etc/lighttpd/lighttpd.conf
    - text: include "vhosts.d/{{ vhosts_conf }}.conf"
    - listen_in:
      - service: lighttpd
{% endfor %}

Prepare Directory for Self Signed SSL Certificate:
  file.directory:
    - name: /etc/lighttpd/ssl/jobst.jobstreet.com
    - makedirs: True

Copy Self Signed Certificate:
  file.managed:
    - name: /etc/lighttpd/ssl/jobst.jobstreet.com/server.pem
    - source: salt://lighttpd/files/server.pem
    - template: jinja
    - listen_in:
      - service: lighttpd

Copy support related files to /var/www/support:
  file.recurse:
    - name: /var/www/support
    - source: salt://lighttpd/files/support
    - dir_mode: 755
    - file_mode: 644

#This will not throw error even if nginx does no exist
Disable and Stop nginx:
  service.dead:
    - name: nginx
    - enable: False

Enable Lighttpd service:
  service.running:
    - name: lighttpd
    - enable: True
    - listen:
      - file: /etc/lighttpd/lighttpd.conf
